<?php
/**
 * Created by PhpStorm.
 * User: alinejun
 * Date: 2019/3/4
 * Time: 22:54
 */
namespace app\admin\controller;

/**
 * 首页控制器
 */


/**
 * 城市控制器
 */
class City extends AdminBase
{

    /**
     * 城市列表
     */
    public function index()
    {

        $where = empty($this->param['pid']) ? ['pid' => 0] : ['pid' => $this->param['pid']];

        $this->assign('list', $this->logicCity->getCityList($where, true, 'sort', DB_LIST_ROWS));

        $this->assign('pid', $where['pid']);

        return $this->fetch('city_list');
    }

    /**
     * 获取城市Select结构数据
     */
    public function getCitySelectData()
    {

        $city_select = $this->logicCity->cityToSelect($this->cityListTree);

        $this->assign('city_select', $city_select);
    }

    /**
     * 城市添加
     */
    public function cityAdd()
    {

        $this->param['module'] = MODULE_NAME;

        IS_POST && $this->jump($this->logicCity->cityAdd($this->param));

        //获取城市Select结构数据
        $this->getCitySelectData();

        !empty($this->param['pid']) && $this->assign('info', ['pid' => $this->param['pid']]);

        return $this->fetch('city_edit');
    }

    /**
     * 城市编辑
     */
    public function cityEdit()
    {

        IS_POST && $this->jump($this->logicCity->cityEdit($this->param));

        $info = $this->logicCity->getCityInfo(['id' => $this->param['id']]);

        $this->assign('info', $info);

        //获取城市Select结构数据
        $this->getCitySelectData();

        return $this->fetch('city_edit');
    }

    /**
     * 数据状态设置
     */
    public function setStatus()
    {

        $this->jump($this->logicAdminBase->setStatus('City', $this->param));
    }

    /**
     * 排序
     */
    public function setSort()
    {

        $this->jump($this->logicAdminBase->setSort('City', $this->param));

    }
}